/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cstddef>
#include <cstdint>
#include <fuzzer/FuzzedDataProvider.h>
#include "codec_drm_decrypt.h"
#include "securec.h"
#ifdef SUPPORT_DRM
#include "imedia_key_session_service.h"
#endif

#define FUZZ_PROJECT_NAME "drmdecryptor_fuzzer"

using namespace std;
using namespace OHOS::MediaAVCodec;
using namespace OHOS::Media;

const uint8_t *fuzzData = nullptr;
size_t fuzzSize = 0;

#define DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(cond, ret)                  \
    do {                                                                    \
        if (!(cond)) {                                                      \
            return ret;                                                     \
        }                                                                   \
    } while (0)

namespace {
const uint32_t KEY_ID_LEN = 16;
const uint32_t IV_LEN = 16;

// for H264
const uint8_t DRM_H264_KEY_ID[] = {
    0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53,
    0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x37};
const uint8_t DRM_H264_IV[] = {
    0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53,
    0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x37};
uint32_t DRM_H264_ENCRYPTED_BUFFER_SIZE = 418;
const uint8_t DRM_H264_SM4C_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd3,
    0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03,
    0xce, 0x64, 0x00, 0x01, 0x31, 0x2d, 0x00, 0x00, 0x2f, 0xaf, 0x0a, 0x27, 0x28, 0x07, 0x8c, 0x18,
    0x9c, 0x00, 0x00, 0x00, 0x01, 0x68, 0xea, 0xac, 0xb2, 0x2c, 0x00, 0x00, 0x01, 0x06, 0x00, 0x05,
    0x98, 0xb8, 0x00, 0xaf, 0xd4, 0x80, 0x00, 0x00, 0x01, 0x06, 0x05, 0x26, 0xdc, 0x45, 0xe9, 0xbd,
    0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef, 0x73, 0x75, 0x6d, 0x61,
    0x20, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2c, 0x76, 0x32, 0x30, 0x31, 0x36, 0x20, 0x2d, 0x31, 0x34,
    0x38, 0x00, 0x80, 0x00, 0x00, 0x01, 0x06, 0x01, 0x02, 0x00, 0x0a, 0x80, 0x00, 0x00, 0x01, 0x06,
    0x05, 0xc8, 0x70, 0xc1, 0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69,
    0x4b, 0x66, 0xf0, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x10, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49,
    0x44, 0x5f, 0x30, 0x37, 0xc0, 0x84, 0x43, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73,
    0x68, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43,
    0xdd, 0x3c, 0x6e, 0x72, 0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72,
    0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f,
    0x6e, 0x74, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x43,
    0x31, 0x7a, 0x62, 0x54, 0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c,
    0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x22, 0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74,
    0x73, 0x22, 0x3a, 0x22, 0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x34, 0x22, 0x7d, 0x80, 0x00, 0x00,
    0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0xff, 0x9f, 0x97, 0x12, 0x77, 0x06, 0xff, 0x81, 0x48, 0xf0,
    0x84, 0xc3, 0xfb, 0x35, 0x95, 0x4d, 0x40, 0x94, 0x6e, 0x1a, 0xd3, 0x6f, 0xb0, 0xc3, 0xae, 0x35,
    0x01, 0x6f, 0x46, 0x26, 0xae, 0x2b, 0x46, 0x6b, 0x81, 0x9f, 0xc1, 0xf9, 0x46, 0x86, 0x5b, 0x62,
    0xaa, 0x0d, 0x2a, 0x39, 0xc0, 0xae, 0x2d, 0x52, 0xef, 0x97, 0x6e, 0xd5, 0x78, 0xec, 0xa4, 0x25,
    0xee, 0xa7, 0xa6, 0xae, 0xed, 0xf3, 0xe7, 0xdf, 0xef, 0xd8, 0x84, 0xb4, 0x45, 0xd4, 0xfb, 0x67,
    0x8c, 0x6c}; //418
const uint8_t DRM_H264_SM4S_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd3,
    0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03,
    0xce, 0x64, 0x00, 0x01, 0x31, 0x2d, 0x00, 0x00, 0x2f, 0xaf, 0x0a, 0x27, 0x28, 0x07, 0x8c, 0x18,
    0x9c, 0x00, 0x00, 0x00, 0x01, 0x68, 0xea, 0xac, 0xb2, 0x2c, 0x00, 0x00, 0x01, 0x06, 0x00, 0x05,
    0x98, 0xb8, 0x00, 0xaf, 0xd4, 0x80, 0x00, 0x00, 0x01, 0x06, 0x05, 0x26, 0xdc, 0x45, 0xe9, 0xbd,
    0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef, 0x73, 0x75, 0x6d, 0x61,
    0x20, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2c, 0x76, 0x32, 0x30, 0x31, 0x36, 0x20, 0x2d, 0x31, 0x34,
    0x38, 0x00, 0x80, 0x00, 0x00, 0x01, 0x06, 0x01, 0x02, 0x00, 0x0a, 0x80, 0x00, 0x00, 0x01, 0x06,
    0x05, 0xc8, 0x70, 0xc1, 0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69,
    0x4b, 0x66, 0xf0, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x10, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49,
    0x44, 0x5f, 0x30, 0x37, 0xc0, 0x84, 0x41, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73,
    0x68, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43,
    0xdd, 0x3c, 0x6e, 0x72, 0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72,
    0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f,
    0x6e, 0x74, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x43,
    0x31, 0x7a, 0x62, 0x54, 0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c,
    0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x22, 0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74,
    0x73, 0x22, 0x3a, 0x22, 0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x34, 0x22, 0x7d, 0x80, 0x00, 0x00,
    0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0xff, 0x9f, 0x97, 0x12, 0x77, 0x06, 0xff, 0x81, 0x48, 0xf0,
    0x84, 0xc3, 0xfb, 0x35, 0x95, 0x4d, 0x40, 0x94, 0x6e, 0x1a, 0xd3, 0x6f, 0xb0, 0xc3, 0xae, 0x35,
    0x01, 0x6f, 0x46, 0x26, 0xae, 0x2b, 0x46, 0x6b, 0x81, 0x9f, 0xc1, 0xf9, 0x46, 0x86, 0x5b, 0x62,
    0xaa, 0x0d, 0x2a, 0x39, 0xc0, 0xae, 0x2d, 0x52, 0xef, 0x97, 0x6e, 0xd5, 0x78, 0xec, 0xa4, 0x25,
    0xee, 0xa7, 0xa6, 0xae, 0xed, 0xf3, 0xe7, 0xdf, 0xef, 0xd8, 0x84, 0xb4, 0x45, 0xd4, 0xfb, 0x67,
    0x8c, 0x6c}; //418
const uint8_t DRM_H264_CBC1_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd3,
    0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03,
    0xce, 0x64, 0x00, 0x01, 0x31, 0x2d, 0x00, 0x00, 0x2f, 0xaf, 0x0a, 0x27, 0x28, 0x07, 0x8c, 0x18,
    0x9c, 0x00, 0x00, 0x00, 0x01, 0x68, 0xea, 0xac, 0xb2, 0x2c, 0x00, 0x00, 0x01, 0x06, 0x00, 0x05,
    0x98, 0xb8, 0x00, 0xaf, 0xd4, 0x80, 0x00, 0x00, 0x01, 0x06, 0x05, 0x26, 0xdc, 0x45, 0xe9, 0xbd,
    0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef, 0x73, 0x75, 0x6d, 0x61,
    0x20, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2c, 0x76, 0x32, 0x30, 0x31, 0x36, 0x20, 0x2d, 0x31, 0x34,
    0x38, 0x00, 0x80, 0x00, 0x00, 0x01, 0x06, 0x01, 0x02, 0x00, 0x0a, 0x80, 0x00, 0x00, 0x01, 0x06,
    0x05, 0xc8, 0x70, 0xc1, 0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69,
    0x4b, 0x66, 0xf0, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x10, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49,
    0x44, 0x5f, 0x30, 0x37, 0xc0, 0x84, 0x45, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73,
    0x68, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43,
    0xdd, 0x3c, 0x6e, 0x72, 0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72,
    0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f,
    0x6e, 0x74, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x43,
    0x31, 0x7a, 0x62, 0x54, 0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c,
    0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x22, 0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74,
    0x73, 0x22, 0x3a, 0x22, 0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x34, 0x22, 0x7d, 0x80, 0x00, 0x00,
    0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0xff, 0x9f, 0x97, 0x12, 0x77, 0x06, 0xff, 0x81, 0x48, 0xf0,
    0x84, 0xc3, 0xfb, 0x35, 0x95, 0x4d, 0x40, 0x94, 0x6e, 0x1a, 0xd3, 0x6f, 0xb0, 0xc3, 0xae, 0x35,
    0x01, 0x6f, 0x46, 0x26, 0xae, 0x2b, 0x46, 0x6b, 0x81, 0x9f, 0xc1, 0xf9, 0x46, 0x86, 0x5b, 0x62,
    0xaa, 0x0d, 0x2a, 0x39, 0xc0, 0xae, 0x2d, 0x52, 0xef, 0x97, 0x6e, 0xd5, 0x78, 0xec, 0xa4, 0x25,
    0xee, 0xa7, 0xa6, 0xae, 0xed, 0xf3, 0xe7, 0xdf, 0xef, 0xd8, 0x84, 0xb4, 0x45, 0xd4, 0xfb, 0x67,
    0x8c, 0x6c}; //418
const uint8_t DRM_H264_CBCS_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd3,
    0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03,
    0xce, 0x64, 0x00, 0x01, 0x31, 0x2d, 0x00, 0x00, 0x2f, 0xaf, 0x0a, 0x27, 0x28, 0x07, 0x8c, 0x18,
    0x9c, 0x00, 0x00, 0x00, 0x01, 0x68, 0xea, 0xac, 0xb2, 0x2c, 0x00, 0x00, 0x01, 0x06, 0x00, 0x05,
    0x98, 0xb8, 0x00, 0xaf, 0xd4, 0x80, 0x00, 0x00, 0x01, 0x06, 0x05, 0x26, 0xdc, 0x45, 0xe9, 0xbd,
    0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef, 0x73, 0x75, 0x6d, 0x61,
    0x20, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2c, 0x76, 0x32, 0x30, 0x31, 0x36, 0x20, 0x2d, 0x31, 0x34,
    0x38, 0x00, 0x80, 0x00, 0x00, 0x01, 0x06, 0x01, 0x02, 0x00, 0x0a, 0x80, 0x00, 0x00, 0x01, 0x06,
    0x05, 0xc8, 0x70, 0xc1, 0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69,
    0x4b, 0x66, 0xf0, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x10, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49,
    0x44, 0x5f, 0x30, 0x37, 0xc0, 0x84, 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73,
    0x68, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43,
    0xdd, 0x3c, 0x6e, 0x72, 0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72,
    0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f,
    0x6e, 0x74, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x43,
    0x31, 0x7a, 0x62, 0x54, 0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c,
    0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x22, 0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74,
    0x73, 0x22, 0x3a, 0x22, 0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x34, 0x22, 0x7d, 0x80, 0x00, 0x00,
    0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0xff, 0x9f, 0x97, 0x12, 0x77, 0x06, 0xff, 0x81, 0x48, 0xf0,
    0x84, 0xc3, 0xfb, 0x35, 0x95, 0x4d, 0x40, 0x94, 0x6e, 0x1a, 0xd3, 0x6f, 0xb0, 0xc3, 0xae, 0x35,
    0x01, 0x6f, 0x46, 0x26, 0xae, 0x2b, 0x46, 0x6b, 0x81, 0x9f, 0xc1, 0xf9, 0x46, 0x86, 0x5b, 0x62,
    0xaa, 0x0d, 0x2a, 0x39, 0xc0, 0xae, 0x2d, 0x52, 0xef, 0x97, 0x6e, 0xd5, 0x78, 0xec, 0xa4, 0x25,
    0xee, 0xa7, 0xa6, 0xae, 0xed, 0xf3, 0xe7, 0xdf, 0xef, 0xd8, 0x84, 0xb4, 0x45, 0xd4, 0xfb, 0x67,
    0x8c, 0x6c}; //418
const uint8_t DRM_H264_NONE_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd3,
    0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03,
    0xce, 0x64, 0x00, 0x01, 0x31, 0x2d, 0x00, 0x00, 0x2f, 0xaf, 0x0a, 0x27, 0x28, 0x07, 0x8c, 0x18,
    0x9c, 0x00, 0x00, 0x00, 0x01, 0x68, 0xea, 0xac, 0xb2, 0x2c, 0x00, 0x00, 0x01, 0x06, 0x00, 0x05,
    0x98, 0xb8, 0x00, 0xaf, 0xd4, 0x80, 0x00, 0x00, 0x01, 0x06, 0x05, 0x26, 0xdc, 0x45, 0xe9, 0xbd,
    0xe6, 0xd9, 0x48, 0xb7, 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef, 0x73, 0x75, 0x6d, 0x61,
    0x20, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2c, 0x76, 0x32, 0x30, 0x31, 0x36, 0x20, 0x2d, 0x31, 0x34,
    0x38, 0x00, 0x80, 0x00, 0x00, 0x01, 0x06, 0x01, 0x02, 0x00, 0x0a, 0x80, 0x00, 0x00, 0x01, 0x06,
    0x05, 0xc8, 0x70, 0xc1, 0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69,
    0x4b, 0x66, 0xf0, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44,
    0x5f, 0x30, 0x37, 0x10, 0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49,
    0x44, 0x5f, 0x30, 0x37, 0xc0, 0x84, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73,
    0x68, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43,
    0xdd, 0x3c, 0x6e, 0x72, 0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72,
    0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f,
    0x6e, 0x74, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x43,
    0x31, 0x7a, 0x62, 0x54, 0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c,
    0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x22, 0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74,
    0x73, 0x22, 0x3a, 0x22, 0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x34, 0x22, 0x7d, 0x80, 0x00, 0x00,
    0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0xff, 0x9f, 0x97, 0x12, 0x77, 0x06, 0xff, 0x81, 0x48, 0xf0,
    0x84, 0xc3, 0xfb, 0x35, 0x95, 0x4d, 0x40, 0x94, 0x6e, 0x1a, 0xd3, 0x6f, 0xb0, 0xc3, 0xae, 0x35,
    0x01, 0x6f, 0x46, 0x26, 0xae, 0x2b, 0x46, 0x6b, 0x81, 0x9f, 0xc1, 0xf9, 0x46, 0x86, 0x5b, 0x62,
    0xaa, 0x0d, 0x2a, 0x39, 0xc0, 0xae, 0x2d, 0x52, 0xef, 0x97, 0x6e, 0xd5, 0x78, 0xec, 0xa4, 0x25,
    0xee, 0xa7, 0xa6, 0xae, 0xed, 0xf3, 0xe7, 0xdf, 0xef, 0xd8, 0x84, 0xb4, 0x45, 0xd4, 0xfb, 0x67,
    0x8c, 0x6c}; //418

// for HEVC
const uint8_t DRM_HEVC_SM4C_KEY_ID[] = {
    0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53,
    0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x32};
const uint8_t DRM_HEVC_SM4C_IV[] = {
    0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53,
    0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x32};
uint32_t DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE = 351;
#ifdef SUPPORT_DRM
const uint8_t DRM_HEVC_SM4C_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x00, 0x01, 0x46, 0x01, 0x50, 0x00, 0x00, 0x01, 0x4e, 0x01, 0x05, 0xc8, 0x70, 0xc1,
    0xdb, 0x9f, 0x66, 0xae, 0x41, 0x27, 0xbf, 0xc0, 0xbb, 0x19, 0x81, 0x69, 0x4b, 0x66, 0xf0, 0x55,
    0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x32, 0x55,
    0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x32, 0x10,
    0x55, 0x44, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x43, 0x49, 0x44, 0x5f, 0x30, 0x32,
    0xc0, 0x84, 0x33, 0x00, 0x00, 0x03, 0x00, 0x00, 0x82, 0x70, 0x73, 0x73, 0x68, 0x00, 0x00, 0x03,
    0x00, 0x00, 0x3d, 0x5e, 0x6d, 0x35, 0x9b, 0x9a, 0x41, 0xe8, 0xb8, 0x43, 0xdd, 0x3c, 0x6e, 0x72,
    0xc4, 0x2c, 0x00, 0x00, 0x03, 0x00, 0x62, 0x7b, 0x22, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
    0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
    0x74, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x61, 0x44, 0x49, 0x32, 0x4e, 0x53, 0x31, 0x7a, 0x62, 0x54,
    0x52, 0x6a, 0x4c, 0x58, 0x52, 0x7a, 0x4c, 0x54, 0x41, 0x3d, 0x22, 0x2c, 0x22, 0x6b, 0x69, 0x64,
    0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x65, 0x6e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x22,
    0x3a, 0x22, 0x73, 0x6d, 0x34, 0x63, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x74, 0x73, 0x22, 0x3a, 0x22,
    0x74, 0x73, 0x2f, 0x68, 0x32, 0x36, 0x35, 0x22, 0x7d, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
    0xe0, 0x24, 0xbe, 0x08, 0x32, 0x96, 0x00, 0x00, 0x03, 0x02, 0x85, 0xda, 0x3c, 0xd7, 0x82, 0x78,
    0x1e, 0xb7, 0x2e, 0xad, 0x4c, 0x59, 0xb2, 0x2b, 0x72, 0x1f, 0xbe, 0xff, 0x1e, 0xbe, 0xf3, 0x1d,
    0xab, 0x9c, 0x2a, 0x50, 0xfd, 0xdd, 0x3c, 0x00, 0xe9, 0xd6, 0xa3, 0x04, 0x0a, 0x7e, 0x9a, 0x02,
    0x7f, 0x3e, 0x3c, 0x00, 0x2c, 0xf7, 0x86, 0xe4, 0x03, 0x5b, 0x6d, 0xe5, 0xfe, 0x5c, 0xe7, 0x88,
    0x6d, 0x44, 0x67, 0x16, 0x38, 0x95, 0x02, 0x3a, 0x34, 0x31, 0x63, 0x0e, 0x9c, 0xe0, 0xe3, 0x70,
    0xcb, 0xc3, 0x4c, 0x5d, 0x21, 0xaa, 0x9e, 0x0d, 0x45, 0x38, 0x56, 0xb9, 0xc9, 0x2b, 0xf7, 0xf5,
    0xe1, 0xd9, 0x13, 0xa0, 0x46, 0xc3, 0xe8, 0x16, 0xe0, 0x78, 0x75, 0xe8, 0x69, 0x5d, 0xc1, 0xe3,
    0x1d, 0xaa, 0x8c, 0xf4, 0x59, 0x75, 0xc2, 0xe1, 0x36, 0x98, 0x4f, 0x83, 0x2e, 0x87, 0x51}; // 351
#endif

// for AVS
const uint8_t DRM_AVS_SM4C_KEY_ID[] = {
    0xd4, 0xb2, 0x01, 0xe4, 0x61, 0xc8, 0x98, 0x96,
    0xcf, 0x05, 0x22, 0x39, 0x8d, 0x09, 0xe6, 0x28 };
const uint8_t DRM_AVS_SM4C_IV[] = {
    0xbf, 0x77, 0xed, 0x51, 0x81, 0xde, 0x36, 0x3e,
    0x52, 0xf7, 0x20, 0x4f, 0x72, 0x14, 0xa3, 0x95};
uint32_t DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE = 238;
#ifdef SUPPORT_DRM
const uint8_t DRM_AVS_SM4C_ENCRYPTED_BUFFER[] = {
    0x00, 0x00, 0x01, 0xB5, 0xDF, 0x80, 0xD4, 0xB2, 0x01, 0xE4, 0x61, 0xC8, 0x98, 0x96, 0xCF, 0x05,
    0x22, 0x39, 0x8D, 0x09, 0xE6, 0x28, 0x10, 0xBF, 0x77, 0xED, 0x51, 0x81, 0xDE, 0x36, 0x3E, 0x52,
    0xF7, 0x20, 0x4F, 0x72, 0x14, 0xA3, 0x95, 0x00, 0x00, 0x01, 0xb6, 0xff, 0xff, 0xff, 0xff, 0xce,
    0x14, 0x92, 0x10, 0x20, 0x82, 0xb5, 0xc0, 0x5e, 0x7b, 0xb4, 0x5a, 0x00, 0x00, 0x01, 0x00, 0xf6,
    0x41, 0x55, 0xf7, 0x4f, 0xbb, 0x05, 0x15, 0xec, 0x11, 0xba, 0x98, 0x92, 0xdc, 0x21, 0x72, 0x75,
    0x52, 0xfd, 0x9b, 0xff, 0x6c, 0x13, 0x75, 0x32, 0x11, 0x9a, 0x1c, 0xd4, 0xac, 0x58, 0x2c, 0x9a,
    0x27, 0x4a, 0xab, 0x5c, 0x5b, 0x5e, 0xe1, 0xe8, 0xb9, 0x80, 0x9b, 0x0c, 0x63, 0xd8, 0xd1, 0xd8,
    0xee, 0x8f, 0xce, 0x56, 0x14, 0xb2, 0xad, 0x30, 0x56, 0x7a, 0x22, 0x72, 0x85, 0x21, 0x1e, 0x47,
    0x75, 0xd1, 0x30, 0xb1, 0x74, 0x5c, 0x0d, 0x75, 0xc4, 0x33, 0xcb, 0xfa, 0x14, 0x2d, 0x36, 0x32,
    0x30, 0xd2, 0x2e, 0x9b, 0xc7, 0xd1, 0x5d, 0x3e, 0xd5, 0xaf, 0xed, 0x52, 0xbb, 0xa3, 0x73, 0xe7,
    0x32, 0xfa, 0x4c, 0x5b, 0x4e, 0x73, 0xbd, 0x75, 0x94, 0x4a, 0x12, 0xfd, 0x73, 0x58, 0x95, 0x0c,
    0x50, 0x6b, 0x91, 0xd7, 0x60, 0x52, 0xed, 0xb4, 0x33, 0xea, 0xee, 0x48, 0xbe, 0xde, 0x22, 0xe4,
    0xa6, 0x48, 0xb8, 0xd5, 0xf7, 0x90, 0x1b, 0x2e, 0xbe, 0x69, 0xad, 0x86, 0xe9, 0x88, 0x23, 0x70,
    0x31, 0x61, 0x5d, 0xe7, 0x60, 0x75, 0x27, 0x29, 0x5e, 0xf5, 0xe5, 0x86, 0x76, 0xb8, 0x42, 0x63,
    0x42, 0x84, 0xbb, 0xb4, 0x48, 0x6c, 0x39, 0xc0, 0x40, 0x80, 0x00, 0x00, 0x01, 0x8f}; // 238
#endif

// for Audio
const uint8_t DRM_AUDIO_KEY_ID[] = {
    0xf3, 0xc5, 0xe0, 0x36, 0x1e, 0x66, 0x54, 0xb2,
    0x8f, 0x80, 0x49, 0xc7, 0x78, 0xb2, 0x39, 0x46};
const uint8_t DRM_AUDIO_IV[] = {
    0xa4, 0x63, 0x1a, 0x15, 0x3a, 0x44, 0x3d, 0xf9,
    0xee, 0xd0, 0x59, 0x30, 0x43, 0xdb, 0x75, 0x19};
uint32_t DRM_AUDIO_ENCRYPTED_BUFFER_SIZE = 65;
const uint8_t DRM_AUDIO_ENCRYPTED_BUFFER[] = {
    0x41, 0x55, 0xf7, 0x4f, 0xbb, 0x05, 0x15, 0xec, 0x11, 0xba, 0x98, 0x92, 0xdc, 0x21, 0x72, 0x75,
    0x52, 0xfd, 0x9b, 0xff, 0x6c, 0x13, 0x75, 0x32, 0x11, 0x9a, 0x1c, 0xd4, 0xac, 0x58, 0x2c, 0x9a,
    0x27, 0x4a, 0xab, 0x5c, 0x5b, 0x5e, 0xe1, 0xe8, 0xb9, 0x80, 0x9b, 0x0c, 0x63, 0xd8, 0xd1, 0xd8,
    0xee, 0x8f, 0xce, 0x56, 0x14, 0xb2, 0xad, 0x30, 0x56, 0x7a, 0x22, 0x72, 0x85, 0x21, 0x1e, 0x47,
    0x75}; // 65
}

namespace OHOS {
namespace DrmDecryptorFuzzer {

void CreateH264MediaCencInfo(MetaDrmCencInfo &cencInfo)
{
    cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC;
    memcpy_s(cencInfo.keyId, sizeof(cencInfo.keyId), DRM_H264_KEY_ID, sizeof(cencInfo.keyId));
    cencInfo.keyIdLen = KEY_ID_LEN;
    memcpy_s(cencInfo.iv, sizeof(cencInfo.iv), DRM_H264_IV, sizeof(cencInfo.iv));
    cencInfo.ivLen = IV_LEN;
    cencInfo.encryptBlocks = 0;
    cencInfo.skipBlocks = 0;
    cencInfo.firstEncryptOffset = 0;
    cencInfo.subSampleNum = 1;
    cencInfo.mode = MetaDrmCencInfoMode::META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_NOT_SET;

    cencInfo.subSamples[0].clearHeaderLen = DRM_H264_ENCRYPTED_BUFFER_SIZE;
    cencInfo.subSamples[0].payLoadLen = 0;
}

bool SetH264MediaData(std::shared_ptr<AVBuffer> drmInBuf, MetaDrmCencInfo &cencInfo, uint32_t mode)
{
    int32_t drmRes = 0;
    switch (mode) {
        case 0x1: // 0x1:SM4-SAMPL SM4S
            cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC;
            drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_H264_ENCRYPTED_BUFFER_SIZE,
                DRM_H264_SM4S_ENCRYPTED_BUFFER, DRM_H264_ENCRYPTED_BUFFER_SIZE);
            break;
        case 0x2: // 0x2:AES CBCS
            cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_AES_CBC;
            drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_H264_ENCRYPTED_BUFFER_SIZE,
                DRM_H264_CBCS_ENCRYPTED_BUFFER, DRM_H264_ENCRYPTED_BUFFER_SIZE);
            break;
        case 0x5: // 0x5:AES CBC1
            cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_AES_CBC;
            drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_H264_ENCRYPTED_BUFFER_SIZE,
                DRM_H264_CBC1_ENCRYPTED_BUFFER, DRM_H264_ENCRYPTED_BUFFER_SIZE);
            break;
        case 0x3: // 0x3:SM4-CBC SM4C
            cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC;
            drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_H264_ENCRYPTED_BUFFER_SIZE,
                DRM_H264_SM4C_ENCRYPTED_BUFFER, DRM_H264_ENCRYPTED_BUFFER_SIZE);
            break;
        case 0x0: // 0x0:NONE
            cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_UNENCRYPTED;
            drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_H264_ENCRYPTED_BUFFER_SIZE,
                DRM_H264_NONE_ENCRYPTED_BUFFER, DRM_H264_ENCRYPTED_BUFFER_SIZE);
            break;
        default:
            break;
    }
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    return true;
}

void H264MediaCencDecrypt(std::shared_ptr<AVBuffer> drmInBuf, std::shared_ptr<AVBuffer> drmOutBuf,
    std::shared_ptr<CodecDrmDecrypt> decryptor, uint32_t mode, int32_t flag)
{
    MetaDrmCencInfo cencInfo;
    CreateH264MediaCencInfo(cencInfo);
    SetH264MediaData(drmInBuf, cencInfo, mode);
    if (flag == 1) {
        std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
            (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
        drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    }
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, DRM_H264_ENCRYPTED_BUFFER_SIZE);
}

void CreateHevcMediaCencInfo(MetaDrmCencInfo &cencInfo)
{
    cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC;
    memcpy_s(cencInfo.keyId, sizeof(cencInfo.keyId), DRM_HEVC_SM4C_KEY_ID, sizeof(cencInfo.keyId));
    cencInfo.keyIdLen = KEY_ID_LEN;
    memcpy_s(cencInfo.iv, sizeof(cencInfo.iv), DRM_HEVC_SM4C_IV, sizeof(cencInfo.iv));
    cencInfo.ivLen = IV_LEN;
    cencInfo.encryptBlocks = 0;
    cencInfo.skipBlocks = 0;
    cencInfo.firstEncryptOffset = 0;
    cencInfo.subSampleNum = 1;
    cencInfo.mode = MetaDrmCencInfoMode::META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_NOT_SET;

    cencInfo.subSamples[0].clearHeaderLen = DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE;
    cencInfo.subSamples[0].payLoadLen = 0;
}

void CreateAvsMediaCencInfo(MetaDrmCencInfo &cencInfo)
{
    cencInfo.algo = MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC;
    memcpy_s(cencInfo.keyId, sizeof(cencInfo.keyId), DRM_AVS_SM4C_KEY_ID, sizeof(cencInfo.keyId));
    cencInfo.keyIdLen = KEY_ID_LEN;
    memcpy_s(cencInfo.iv, sizeof(cencInfo.iv), DRM_AVS_SM4C_IV, sizeof(cencInfo.iv));
    cencInfo.ivLen = IV_LEN;
    cencInfo.encryptBlocks = 0;
    cencInfo.skipBlocks = 0;
    cencInfo.firstEncryptOffset = 0;
    cencInfo.subSampleNum = 1;
    cencInfo.mode = MetaDrmCencInfoMode::META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_NOT_SET;

    cencInfo.subSamples[0].clearHeaderLen = DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE;
    cencInfo.subSamples[0].payLoadLen = 0;
}

void CreateAudioCencInfo(MetaDrmCencInfo &cencInfo, MetaDrmCencAlgorithm algo)
{
    cencInfo.algo = algo;
    memcpy_s(cencInfo.keyId, sizeof(cencInfo.keyId), DRM_AUDIO_KEY_ID, sizeof(cencInfo.keyId));
    cencInfo.keyIdLen = KEY_ID_LEN;
    memcpy_s(cencInfo.iv, sizeof(cencInfo.iv), DRM_AUDIO_IV, sizeof(cencInfo.iv));
    cencInfo.ivLen = IV_LEN;
    cencInfo.encryptBlocks = 0;
    cencInfo.skipBlocks = 0;
    cencInfo.firstEncryptOffset = 0;
    cencInfo.subSampleNum = 0;
    cencInfo.mode = MetaDrmCencInfoMode::META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_SET;
}

bool AudioCencDecrypt(std::shared_ptr<AVBuffer> drmInBuf, std::shared_ptr<AVBuffer> drmOutBuf,
    std::shared_ptr<CodecDrmDecrypt> decryptor, MetaDrmCencAlgorithm algo, int32_t flag)
{
    MetaDrmCencInfo cencInfo;
    CreateAudioCencInfo(cencInfo, algo);

    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_AUDIO_ENCRYPTED_BUFFER_SIZE,
        DRM_AUDIO_ENCRYPTED_BUFFER, DRM_AUDIO_ENCRYPTED_BUFFER_SIZE);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);

    if (flag == 1) {
        std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
            (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
        drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    }
    decryptor->DrmAudioCencDecrypt(drmInBuf, drmOutBuf, DRM_AUDIO_ENCRYPTED_BUFFER_SIZE);
    return true;
}

bool SetCodecNameFuzzTest(FuzzedDataProvider *provider)
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);
    static uint8_t setCodecNameFuzzTestFlag = 0;
    if (setCodecNameFuzzTestFlag == 0) {
        decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avc");
        decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.hevc");
        decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avs");
        decryptor->SetCodecName("OH.Media.Codec.Decoder.Audio.mp4a-latm");
        setCodecNameFuzzTestFlag = 1;
    }
    std::string codecName = provider->ConsumeRandomLengthString();
    decryptor->SetCodecName(codecName);
    return true;
}

#ifdef SUPPORT_DRM
bool SetDecryptionConfigFuzzTest(FuzzedDataProvider *provider)
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);
    static uint8_t setDecryptionConfigFuzzTestFlag = 0;
    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    if (setDecryptionConfigFuzzTestFlag == 0) {
        bool svpFlag = false;
        decryptor->SetDecryptionConfig(session, svpFlag);
        setDecryptionConfigFuzzTestFlag = 1;
    }
    bool svpFlag = provider->ConsumeBool();
    decryptor->SetDecryptionConfig(session, svpFlag);
    return true;
}

bool DrmH264VideoCencDecrypt()
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avc");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_H264_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_H264_ENCRYPTED_BUFFER_SIZE)), false);
    drmInBuf->memory_->SetSize(DRM_H264_ENCRYPTED_BUFFER_SIZE);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_H264_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_H264_ENCRYPTED_BUFFER_SIZE)), false);

    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x0, 0);
    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x1, 1); // 0x1:SM4-SAMPL SM4S
    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x2, 1); // 0x2:AES CBCS
    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x5, 1); // 0x5:AES CBC1
    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x3, 1); // 0x3:SM4-CBC SM4C
    H264MediaCencDecrypt(drmInBuf, drmOutBuf, decryptor, 0x0, 1); // 0x0:NONE
    drmOutBuf->memory_->SetSize(DRM_H264_ENCRYPTED_BUFFER_SIZE);
    return true;
}

bool DrmH264VideoCencDecryptFuzzTest()
{
    uint32_t dataSize = static_cast<uint32_t>(fuzzSize);
    static uint8_t drmH264VideoCencDecryptFuzzTestFlag = 0;
    if (drmH264VideoCencDecryptFuzzTestFlag == 0) {
        DrmH264VideoCencDecrypt();
        drmH264VideoCencDecryptFuzzTestFlag = 1;
    }
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avc");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), dataSize, fuzzData, dataSize);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(dataSize);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);

    MetaDrmCencInfo cencInfo;
    CreateH264MediaCencInfo(cencInfo);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, dataSize);
    drmOutBuf->memory_->SetSize(dataSize);
    return true;
}

bool DrmHevcVideoCencDecrypt()
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.hevc");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE)), false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE,
        DRM_HEVC_SM4C_ENCRYPTED_BUFFER, DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE)), false);

    MetaDrmCencInfo cencInfo;
    CreateHevcMediaCencInfo(cencInfo);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE);
    drmOutBuf->memory_->SetSize(DRM_HEVC_SM4C_ENCRYPTED_BUFFER_SIZE);
    return true;
}

bool DrmHevcVideoCencDecryptFuzzTest()
{
    uint32_t dataSize = static_cast<uint32_t>(fuzzSize);
    static uint8_t drmHevcVideoCencDecryptFuzzTestFlag = 0;
    if (drmHevcVideoCencDecryptFuzzTestFlag == 0) {
        DrmHevcVideoCencDecrypt();
        drmHevcVideoCencDecryptFuzzTestFlag = 1;
    }
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.hevc");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), dataSize, fuzzData, dataSize);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(dataSize);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);

    MetaDrmCencInfo cencInfo;
    CreateHevcMediaCencInfo(cencInfo);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, dataSize);
    drmOutBuf->memory_->SetSize(dataSize);
    return true;
}

bool DrmAvsVideoCencDecrypt()
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avs");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE)), false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE,
        DRM_AVS_SM4C_ENCRYPTED_BUFFER, DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE)), false);

    MetaDrmCencInfo cencInfo;
    CreateAvsMediaCencInfo(cencInfo);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE);
    drmOutBuf->memory_->SetSize(DRM_AVS_SM4C_ENCRYPTED_BUFFER_SIZE);
    return true;
}

bool DrmAvsVideoCencDecryptFuzzTest()
{
    uint32_t dataSize = static_cast<uint32_t>(fuzzSize);
    static uint8_t drmAvsVideoCencDecryptFuzzTestFlag = 0;
    if (drmAvsVideoCencDecryptFuzzTestFlag == 0) {
        DrmAvsVideoCencDecrypt();
        drmAvsVideoCencDecryptFuzzTestFlag = 1;
    }
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);

    decryptor->SetCodecName("OH.Media.Codec.Decoder.Video.avs");

    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), dataSize, fuzzData, dataSize);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(dataSize);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);

    MetaDrmCencInfo cencInfo;
    CreateAvsMediaCencInfo(cencInfo);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmVideoCencDecrypt(drmInBuf, drmOutBuf, dataSize);
    drmOutBuf->memory_->SetSize(dataSize);
    return true;
}

bool DrmAudioCencDecryptTest()
{
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);
    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE)), false);
    drmInBuf->memory_->SetSize(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator,
        static_cast<int32_t>(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(
        (drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE)), false);

    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_UNENCRYPTED, 0);
    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_AES_CTR, 1);
    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CTR, 1);
    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_AES_CBC, 1);
    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_SM4_CBC, 1);
    AudioCencDecrypt(drmInBuf, drmOutBuf, decryptor, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_UNENCRYPTED, 1);
    drmOutBuf->memory_->SetSize(DRM_AUDIO_ENCRYPTED_BUFFER_SIZE);
    return true;
}

bool DrmAudioCencDecryptFuzzTest()
{
    uint32_t dataSize = static_cast<uint32_t>(fuzzSize);
    static uint8_t drmAudioCencDecryptFuzzTestFlag = 0;
    if (drmAudioCencDecryptFuzzTestFlag == 0) {
        DrmAudioCencDecryptTest();
        drmAudioCencDecryptFuzzTestFlag = 1;
    }
    std::shared_ptr<CodecDrmDecrypt> decryptor = std::make_shared<CodecDrmDecrypt>();
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(decryptor != nullptr, false);
    sptr<DrmStandard::IMediaKeySessionService> session = nullptr;
    bool svpFlag = false;
    decryptor->SetDecryptionConfig(session, svpFlag);

    MemoryFlag memFlag = MEMORY_READ_WRITE;
    std::shared_ptr<AVAllocator> avAllocator = AVAllocatorFactory::CreateSharedAllocator(memFlag);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(avAllocator != nullptr, false);
    std::shared_ptr<AVBuffer> drmInBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmInBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);
    int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), dataSize, fuzzData, dataSize);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmRes == 0, false);
    drmInBuf->memory_->SetSize(dataSize);

    std::shared_ptr<AVBuffer> drmOutBuf = AVBuffer::CreateAVBuffer(avAllocator, static_cast<int32_t>(dataSize));
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_ != nullptr, false);
    DRM_DECRYPTOR_FUZZ_CHECK_AND_RETURN_RET(drmOutBuf->memory_->GetCapacity() == static_cast<int32_t>(dataSize),
        false);

    MetaDrmCencInfo cencInfo;
    CreateAudioCencInfo(cencInfo, MetaDrmCencAlgorithm::META_DRM_ALG_CENC_AES_CBC);
    std::vector<uint8_t> drmCencVec(reinterpret_cast<uint8_t *>(&cencInfo),
        (reinterpret_cast<uint8_t *>(&cencInfo)) + sizeof(MetaDrmCencInfo));
    drmInBuf->meta_->SetData(Media::Tag::DRM_CENC_INFO, std::move(drmCencVec));
    decryptor->DrmAudioCencDecrypt(drmInBuf, drmOutBuf, dataSize);
    drmOutBuf->memory_->SetSize(dataSize);
    return true;
}
#endif

} // namespace DrmDecryptorFuzzer
} // namespace OHOS

/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    /* Run your code on data */
    if (data == nullptr) {
        return 0;
    }
    if (size < sizeof(int64_t)) {
        return 0;
    }
    fuzzData = data;
    fuzzSize = size;
    FuzzedDataProvider fdp(data, size);
    OHOS::DrmDecryptorFuzzer::SetCodecNameFuzzTest(&fdp);
#ifdef SUPPORT_DRM
    OHOS::DrmDecryptorFuzzer::SetDecryptionConfigFuzzTest(&fdp);
    OHOS::DrmDecryptorFuzzer::DrmH264VideoCencDecryptFuzzTest();
    OHOS::DrmDecryptorFuzzer::DrmHevcVideoCencDecryptFuzzTest();
    OHOS::DrmDecryptorFuzzer::DrmAvsVideoCencDecryptFuzzTest();
    OHOS::DrmDecryptorFuzzer::DrmAudioCencDecryptFuzzTest();
#endif
    return 0;
}
